package it.txt.access.capability.commons.schema;

import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;

/**
 *
 * @author seccia
 */
public class CapabilityNamespacesMapper extends NamespacePrefixMapper {

    // Provided namespaces
    public final static QName ACCESS_RIGHTS_CAPABILITY_QNAME =
            new QName("http://schema.capability.access.txt.it", "AccessRightsCapability", "pol");
    public final static QName CAPABILITY_DEMO_REQUEST_QNAME =
            new QName("http://schema.demo.capability.access.txt.it", "CapabilityRequest", "dem");
    public final static QName CAPABILITY_DEMO_RESPONSE_QNAME =
            new QName("http://schema.demo.capability.access.txt.it", "CapabilityResponse", "dem");

    // Imported Nemspaces
    public final static String IMPORTED_SCHEMA_SAML_NS = "urn:oasis:names:tc:SAML:2.0:assertion";
    public final static String IMPORTED_SCHEMA_SAML_PREFIX = "saml";
    public final static String IMPORTED_SCHEMA_XACML_QNAME_NS = "urn:oasis:names:tc:xacml:3.0:core:schema:wd-17";
    public final static String IMPORTED_SCHEMA_XACML_QNAME_PREFIX = "xacml";    
    public final static String IMPORTED_SCHEMA_XENC_NS = "http://www.w3.org/2001/04/xmlenc#";
    public final static String IMPORTED_SCHEMA_XENC_PREFIX = "xenc";    
    public final static String IMPORTED_SCHEMA_XS_NS = "http://www.w3.org/XML/1998/namespace";
    public final static String IMPORTED_SCHEMA_XS_PREFIX = "xs";
    public final static String IMPORTED_SCHEMA_DS_NS = "http://www.w3.org/2000/09/xmldsig#";
    public final static String IMPORTED_SCHEMA_DS_PREFIX = XMLConstants.NULL_NS_URI;

    @Override
    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
        if (namespaceUri.equals(IMPORTED_SCHEMA_SAML_NS)) {
            return IMPORTED_SCHEMA_SAML_PREFIX;
        } else if (namespaceUri.equals(IMPORTED_SCHEMA_XACML_QNAME_NS)) {
            return IMPORTED_SCHEMA_XACML_QNAME_PREFIX;
        } else if (namespaceUri.equals(IMPORTED_SCHEMA_XENC_NS)) {
            return IMPORTED_SCHEMA_XENC_PREFIX;
        } else if (namespaceUri.equals(IMPORTED_SCHEMA_XS_NS)) {
            return IMPORTED_SCHEMA_XS_PREFIX;
        } else if (namespaceUri.equals(IMPORTED_SCHEMA_DS_NS)) {
            return IMPORTED_SCHEMA_DS_PREFIX;
        } else if (namespaceUri.equals(ACCESS_RIGHTS_CAPABILITY_QNAME.getNamespaceURI())) {
            return ACCESS_RIGHTS_CAPABILITY_QNAME.getPrefix();
        } else if (namespaceUri.equals(CAPABILITY_DEMO_REQUEST_QNAME.getNamespaceURI())) {
            return CAPABILITY_DEMO_REQUEST_QNAME.getPrefix();
        } else if (namespaceUri.equals(CAPABILITY_DEMO_RESPONSE_QNAME.getNamespaceURI())) {
            return CAPABILITY_DEMO_RESPONSE_QNAME.getPrefix();
        } else {
            return XMLConstants.NULL_NS_URI;
        }
    }
}
